package com.haier.uos.weather.collection.config;

import com.haier.uos.weather.collection.job.WeatherDataCollectionJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    private static final int TIME = 1800;

    @Bean
    public JobDetail weatherDataCollectionJobDetail() {
        return JobBuilder.newJob(WeatherDataCollectionJob.class)
                .withIdentity("weatherDataCollectionJobDetail")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger weatherDataCollectionTrigger() {
        SimpleScheduleBuilder sechedBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(TIME).repeatForever();
        return TriggerBuilder.newTrigger().withIdentity("weatherDataCollectionTrigger")
                .forJob(weatherDataCollectionJobDetail())
                .withSchedule(sechedBuilder)
                .build();
    }

}
